<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* function fn(a){
      if(typeof a !== 'number') {
        // 主动抛出错误
        var error = new Error('变量a必须必须时number')
        console.log(error);
        throw(err); //  抛出错误 
      }
      console.log("变量a的数据类型必须时number");
    }
    fn('aaaa'); */
    
    //  try catch 错误捕获

    /* console.log(1);
    try{
      console.log(a);
    }catch(err){
      console.log('try里面报错了', err);
    }
    console.log(2); */

    btn.onclick = function(e){
      try{
        e.stopPropagation();
      }catch(err){
        e.cancelBubble = true;
      }
      
    }
  </script>
</body>
</html>